//
//  CellOfDetail.m
//  PetAPP
//
//  Created by apple on 16/3/7.
//  Copyright © 2016年 Yuming. All rights reserved.
//

#import "CellOfDetail.h"
#import "ModelOfDetailOfPage.h"
#import <YYWebImage.h>
#import <DKNightVersion.h>
#import "NetworkingHandle.h"
#import <AVFoundation/AVFoundation.h>


#define WIDTH self.frame.size.width

@interface CellOfDetail ()

@property (nonatomic, retain) UIView *userView;

@property (nonatomic, retain) UIView *picsView;

@property (nonatomic, retain) UIView *tagView;

@property (nonatomic, retain) UIView *likeUserView;

@property (nonatomic, retain) UIView *timeAndLookView;

@property (nonatomic, assign) CGFloat headerHight;

@property (nonatomic, retain) UIImageView *viewOfUserFace;

@property (nonatomic, retain) UILabel *labelOfAuthor;

@property (nonatomic, retain) UILabel *labelOfAddress;

@property (nonatomic, retain) UIButton *buttonOfisfollow;

@property (nonatomic, retain) UILabel *labelOfPicNum;

@property (nonatomic, retain) UILabel *labelOfTime;

@property (nonatomic, assign) BOOL flag;

@property (nonatomic, retain) ModelOfDetailOfPage *modelOfContent;

@property (nonatomic,retain)AVPlayer *player;

@property (nonatomic,retain)AVPlayerLayer *playerLayer;

@property (nonatomic,retain)AVPlayerItem *playerItem;

@property (nonatomic, assign) CGFloat totalMovieDuration; // 保存该视频资源的总时长，快进或快退的时候要用

@property (nonatomic, retain) UIView *playerView;

@property (nonatomic, retain) UILabel *timeLabel;

@property (nonatomic, retain) UISlider *ProgressSlider;

@property (nonatomic, retain) UIImageView *videoPic;

@end

@implementation CellOfDetail

- (void)dealloc {
    [_playerView release];
    [_player release];
    [_playerLayer release];
    [_playerItem release];
    [_labelOfTime release];
    [_modelOfContent release];
    [_userView release];
    [_picsView release];
    [_tagView release];
    [_likeUserView release];
    [_timeAndLookView release];
    [_viewOfUserFace release];
    [_labelOfAuthor release];
    [_labelOfAddress release];
    [_buttonOfisfollow release];
    [_labelOfPicNum release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
        self.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:0.2952 green:0.2952 blue:0.2952 alpha:1.0]);
    }
    
    return self;
}

- (void)createSubViews {
#pragma mark - 创建用户信息的view
    self.userView  = [[UIView alloc] init];
    [self addSubview:self.userView];
    [_userView release];
    
    
    
    self.viewOfUserFace = [[UIImageView alloc] init];
    [self.userView addSubview:self.viewOfUserFace];
    [_viewOfUserFace release];
    
    
    self.labelOfAuthor = [[UILabel alloc] init];
    [self.userView addSubview:self.labelOfAuthor];
    [_labelOfAuthor release];
    self.labelOfAuthor.font = [UIFont systemFontOfSize:17];
    self.labelOfAuthor.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    /** 设置时间图标 */
    UIImageView *timeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shijian"]];
    timeImageView.frame = CGRectMake(60, 27, 20, 19);
    [self.userView addSubview:timeImageView];
    [timeImageView release];
    
    
    
    self.labelOfTime = [[UILabel alloc] init];
    [self.userView addSubview:_labelOfTime];
    [_labelOfTime release];
    self.labelOfTime.textColor = [UIColor grayColor];
    self.labelOfTime.font = [UIFont systemFontOfSize:15];
    
    self.labelOfAddress = [[UILabel alloc] init];
    [self.userView addSubview:self.labelOfAddress];
    [_labelOfAddress release];
    self.labelOfAddress.dk_textColorPicker = DKColorWithColors([UIColor grayColor], [UIColor whiteColor]);
    self.labelOfAddress.font = [UIFont systemFontOfSize:14];
    
    
    self.buttonOfisfollow = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.userView addSubview:self.buttonOfisfollow];
    self.buttonOfisfollow.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.buttonOfisfollow dk_setTitleColorPicker:DKColorWithColors([UIColor blackColor], [UIColor whiteColor]) forState:UIControlStateNormal];
    [self.buttonOfisfollow addTarget:self action:@selector(handleAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
#pragma mark ** 创建内容的view
    
#pragma mark ** 创建标签的view
    self.tagView = [[UIView alloc] init];
    [self addSubview:self.tagView];
    [_tagView release];
    
    
    UIImageView *imageViewOfMark = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 20, 20)];
    imageViewOfMark.image = [UIImage imageNamed:@"biaoqian"];
    for (int i = 0 ; i < 5; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.tagView addSubview:button];
        button.titleLabel.font = [UIFont systemFontOfSize:17];
        
        [button dk_setTitleColorPicker:DKColorWithColors([UIColor colorWithRed:0.0796 green:0.2411 blue:0.9941 alpha:1.0], [UIColor whiteColor]) forState:UIControlStateNormal];
        
        button.tag = i + 10;
    }
    [self.tagView addSubview:imageViewOfMark];
    [imageViewOfMark release];
    
    
    
    
#pragma mark ** 创建喜欢用户头像的view
    self.likeUserView = [[UIView alloc] init];
    [self addSubview:self.likeUserView];
    [_likeUserView release];
    
    
    UIImageView *likeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"like"]];
    [self.likeUserView addSubview:likeImageView];
    [likeImageView release];
    likeImageView.frame = CGRectMake(10, 15, 20, 20);
    
    
    
#pragma mark ** 创建时间和观看数量的view
    self.timeAndLookView = [[UIView alloc] init];
    [self addSubview:self.timeAndLookView];
    [_timeAndLookView release];
    
}

#pragma mark - 通过model赋值
- (void)handleDataWithModel:(ModelOfDetailOfPage *)model {
    self.modelOfContent = model;
    
#pragma mark ** 显示用户信息的view
    [self.viewOfUserFace yy_setImageWithURL:[NSURL URLWithString:model.userface] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
    
    self.labelOfAuthor.text = model.author;
    
    
    self.labelOfAddress.text = model.address;
    
    
   
    if ([model.isfollow isEqual:@0]) {/**< 已经关注 */
        self.buttonOfisfollow.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
        self.buttonOfisfollow.layer.borderWidth = 1;
        self.buttonOfisfollow.layer.borderColor = [UIColor grayColor].CGColor;
        [self.buttonOfisfollow setTitle:@"已关注" forState:UIControlStateNormal];
        self.flag = YES;
        
    }else {
        
        self.buttonOfisfollow.dk_backgroundColorPicker = DKColorWithColors([UIColor colorWithRed:1.0 green:0.8423 blue:0.2839 alpha:1.0], [UIColor blackColor]);
        self.buttonOfisfollow.layer.borderWidth = 0;
        [self.buttonOfisfollow setTitle:@"✚ 关注" forState:UIControlStateNormal];
        self.flag = NO;
        
    }
    
#pragma mark ** 显示图片的view
    /** 上方的内容 */
    UILabel *labelOfSubject = [[UILabel alloc] init];
    labelOfSubject.numberOfLines = 0;
    labelOfSubject.text = model.subject;
    CGRect messageRect = [model.subject boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:20]} context:nil];
    labelOfSubject.frame = CGRectMake(15, CGRectGetMaxY(self.userView.frame) + 10, [UIScreen mainScreen].bounds.size.width - 30 , messageRect.size.height);
    [self addSubview:labelOfSubject];
    [labelOfSubject release];
    labelOfSubject.font = [UIFont systemFontOfSize:20];
    labelOfSubject.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
    
    for (int i = 0 ; i < model.message.count; i++) {
        
        if (0 == i) {
            UILabel *labelOfContent = [[UILabel alloc] init];
            [self addSubview:labelOfContent];
            [labelOfContent release];
            labelOfContent.numberOfLines = 0;
            labelOfContent.text = model.content;
            CGRect contentRect = [model.content boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]} context:nil];
            labelOfContent.font = [UIFont systemFontOfSize:16];
            labelOfContent.dk_textColorPicker =  DKColorWithColors([UIColor colorWithRed:0.5739 green:0.5739 blue:0.5739 alpha:1.0], [UIColor whiteColor]);
            labelOfContent.tag = 200;
            
            labelOfContent.frame = CGRectMake(15, CGRectGetMaxY(labelOfSubject.frame) + 10, [UIScreen mainScreen].bounds.size.width - 30, contentRect.size.height);
        }else {
            if ([[model.message[i] valueForKey:@"type"] isEqualToString:@"article"]) {
                UILabel *labelOfContent = [[UILabel alloc] init];
                [self addSubview:labelOfContent];
                [labelOfContent release];
                labelOfContent.numberOfLines = 0;
                labelOfContent.text = model.content;
                CGRect contentRect = [model.content boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:20]} context:nil];
                labelOfContent.font = [UIFont systemFontOfSize:20];
                labelOfContent.dk_textColorPicker =  DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
                labelOfContent.tag = i + 200;
                
                labelOfContent.frame = CGRectMake(15, CGRectGetMaxY([self viewWithTag:i - 1 + 200].frame) + 10, [UIScreen mainScreen].bounds.size.width - 30, contentRect.size.height);
            }else if ([[model.message[i] valueForKey:@"type"] isEqualToString:@"video"]){
#pragma mark - 创建视频
                self.playerView = [[UIView alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY([self viewWithTag:i - 1 + 200].frame) + 10, [UIScreen mainScreen].bounds.size.width - 30, [UIScreen mainScreen].bounds.size.width - 30)];
                [self addSubview:_playerView];
                [_playerView release];
                self.playerView.tag = i + 200;
                NSString *urlStr = [model.message[i] valueForKey:@"content"];
                
                urlStr =[urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
                
                NSURL *url=[NSURL URLWithString:urlStr];
                
                //创建视频项目对象/ /mµ
                self.playerItem = [[AVPlayerItem alloc] initWithURL:url];
                
                //创建视频播放器对象
                self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
                
                //创建承载播放器的AVPlayerLayer对象
                self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
                
                self.playerLayer.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 30, [UIScreen mainScreen].bounds.size.width - 30);
               
                
                
                //视频填充模式
                self.playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
                
                //将播放器添加到playerView的layer层上
                [self.playerView.layer insertSublayer:self.playerLayer atIndex:0];
                
                self.playerView.backgroundColor = [UIColor whiteColor];
                
                
                self.videoPic = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 30, [UIScreen mainScreen].bounds.size.width - 30)];
                [self addSubview:_videoPic];
                [_videoPic release];
                self.videoPic.center = self.playerView.center;
                
                [self.videoPic yy_setImageWithURL:[NSURL URLWithString:[model.message[i] valueForKey:@"coverImg"]] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
                self.videoPic.userInteractionEnabled = YES;
                UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
                [self addSubview:view];
                [view release];
                view.tag = 2333;
                view.center = self.playerView.center;
                view.layer.cornerRadius = 40;
                view.layer.borderColor = [UIColor whiteColor].CGColor;
                view.layer.borderWidth = 2;
                UIBezierPath *backgroundPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 3, 80, 80) cornerRadius:40];
                UITapGestureRecognizer *tapOfPlay = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapActionPlay:)];
                [view addGestureRecognizer:tapOfPlay];
                [tapOfPlay release];
                view.layer.shadowPath = backgroundPath.CGPath;
                view.layer.shadowOpacity = 0.4;
                view.layer.shadowRadius = 0;
                view.layer.shadowColor = [UIColor blackColor].CGColor;
                UIImageView *viewOfimage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
                viewOfimage.image = [UIImage imageNamed:@"bofang"];
                viewOfimage.center = view.center;
                [self addSubview:viewOfimage];
                [viewOfimage release];
                viewOfimage.tag = 2334;
                
                
                
                //添加通知
                [self addNotificationCenters];
                
            }else {
                UIImageView *imageView = [[UIImageView alloc] init];
                [self addSubview:imageView];
                [imageView release];
                [imageView yy_setImageWithURL:[NSURL URLWithString:[model.message[i] objectForKey:@"contentbig"]] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
                imageView.tag = i + 200;
                
                CGFloat height = ([UIScreen mainScreen].bounds.size.width - 30) * [[model.message[i] objectForKey:@"height"] floatValue] / [[model.message[i] objectForKey:@"width"] floatValue];
                
                imageView.frame = CGRectMake(15, CGRectGetMaxY([self viewWithTag:i - 1 + 200].frame) + 10, [UIScreen mainScreen].bounds.size.width - 30, height);
               
            }
        
        }
        
    }
    
    self.tagView.frame = CGRectMake(0, CGRectGetMaxY([self viewWithTag:self.modelOfContent.message.count - 1 + 200].frame) + 10, WIDTH, 20);
    
    self.likeUserView.frame = CGRectMake(0, CGRectGetMaxY(self.tagView.frame) + 5,WIDTH , 50);
    
    self.timeAndLookView.frame = CGRectMake(0, CGRectGetMaxY(self.likeUserView.frame) + 5,WIDTH , 30);

    

#pragma mark ** 显示标签的view
    
    NSArray *tagArr = model.tags;
    for (int i = 0; i < tagArr.count; i++) {
        NSString *str = [tagArr[i] objectForKey:@"tagname"];
        
        CGRect buttonFrame = [str boundingRectWithSize:CGSizeMake(0, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:17]} context:nil];
        
        UIButton *button = [self viewWithTag:(i + 10)];
        UIButton *lastButton = [self viewWithTag:(i + 9)];
        [button setTitle:str forState:UIControlStateNormal];
        if (i > 2) button.hidden = YES;
        if (i != 0) {
            button.frame = CGRectMake(CGRectGetMaxX(lastButton.frame) + 5, 0, buttonFrame.size.width + 2, 20);
        }else {
            button.frame = CGRectMake(35, 0, buttonFrame.size.width + 10, 20);
        }
        
    }
    
  
    
#pragma mark ** 显示喜欢用户头像的view
    
    for (int i = 0; i < model.recommendArr.count; i++) {
        if (i < 9) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(35 + i * 40 + i * 10, 5, 40, 40)];
            [self.likeUserView addSubview:imageView];
            [imageView release];
            imageView.tag = i + 10;
            imageView.layer.cornerRadius = imageView.frame.size.width / 2;
            imageView.layer.masksToBounds = YES;
            [imageView yy_setImageWithURL:[NSURL URLWithString:[model.recommendArr[i] objectForKey:@"userface"]] options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
            
        }
        
    }
    
    
    /** 观看数量图标 */
    UIImageView *lookImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"guankan"]];
    lookImageView.frame = CGRectMake(10, 5, 20, 20);
    [self.timeAndLookView addSubview:lookImageView];
    [lookImageView release];
    
    UILabel *labelOfViews = [[UILabel alloc] initWithFrame:CGRectMake(35, 5, 40, 20)];
    [self.timeAndLookView addSubview:labelOfViews];
    [labelOfViews release];
    labelOfViews.text = model.views;
    labelOfViews.textColor = [UIColor grayColor];
    labelOfViews.font = [UIFont systemFontOfSize:15];
    
}

#pragma mark - 设置高度
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
//    [super applyLayoutAttributes:layoutAttributes];
    
    
    self.userView.frame = CGRectMake(0, 0, WIDTH, 50);
    
    self.viewOfUserFace.frame = CGRectMake(10, 5, 40, 40);
    self.viewOfUserFace.layer.cornerRadius = self.viewOfUserFace.frame.size.width / 2;
    self.viewOfUserFace.layer.masksToBounds = YES;
    
    
    self.labelOfAuthor.frame = CGRectMake(60, 5, 150, 20);
    
    
    /** 计算多久之前的帖子 */
    NSDate *tempDate = [NSDate dateWithTimeIntervalSince1970:self.modelOfContent.dateline.intValue];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    [dateFormatter setDateFormat:@"HH:mm"];
    NSString *strDate = [dateFormatter stringFromDate:tempDate];
    [dateFormatter setDateFormat:@"MM-dd"];
    NSString *str2Date = [dateFormatter stringFromDate:tempDate];
    [dateFormatter release];
    
    NSDate *now = [NSDate date];
    NSTimeInterval time = [now timeIntervalSince1970];
    float seconds = (int)time - self.modelOfContent.dateline.doubleValue;
    float points = seconds / 60;
    if (points < 60) {
        self.labelOfTime.text = [NSString stringWithFormat:@"%d分钟前", (int)points];
        
    }else if (points > 60 && points < 3600) {
        
        self.labelOfTime.text = [NSString stringWithFormat:@"%@",strDate];
    }else {
        self.labelOfTime.text = [NSString stringWithFormat:@"%@",str2Date];
    }
    
    CGRect dateText = [self.labelOfTime.text boundingRectWithSize:CGSizeMake(0, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:15]} context:nil];
    self.labelOfTime.frame = CGRectMake(80, 26, dateText.size.width, 20);
    
    self.labelOfAddress.frame = CGRectMake(CGRectGetMaxX(self.labelOfTime.frame) + 10, 26, 150, 19);
    
    self.buttonOfisfollow.frame = CGRectMake(WIDTH - (15 + 80), 10, 80, 30);
    self.buttonOfisfollow.layer.cornerRadius = 4;

}



#pragma mark - 点击关注按钮
- (void)handleAction:(UIButton *)button {
    
    if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"loginState"] boolValue]) {
        NSString *url = nil;
        NSString *body = nil;
        if (self.flag) {
            self.flag = NO;
            self.buttonOfisfollow.dk_backgroundColorPicker = DKColorWithColors([UIColor colorWithRed:1.0 green:0.8423 blue:0.2839 alpha:1.0], [UIColor blackColor]);
            self.buttonOfisfollow.layer.borderWidth = 0;
            [self.buttonOfisfollow setTitle:@"✚ 关注" forState:UIControlStateNormal];
            
            
            url = @"http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=followdel";
            body = [NSString stringWithFormat:@"follow_uid=%@&follow_username=%@&service=followdel&sign=66d2767ac9ae84958d179e971aadb987&version=d1bd83a33f1a841ab7fda32449746cc4", self.modelOfContent.authorid, self.modelOfContent.author];
        }else {
            self.flag = YES;
            self.buttonOfisfollow.backgroundColor = [UIColor whiteColor];
            self.buttonOfisfollow.layer.borderWidth = 1;
            self.buttonOfisfollow.layer.borderColor = [UIColor grayColor].CGColor;
            [self.buttonOfisfollow setTitle:@"已关注" forState:UIControlStateNormal];
            
            url = @"http://bbs.chinapet.com/plugin.php?id=leepet_thread:api&action=followadd";
            body = [NSString stringWithFormat:@"follow_uid=%@&follow_username=%@&service=followadd&sign=7f1464eb84b4fdd61f6afb4fcf6cfe06&version=d1bd83a33f1a841ab7fda32449746cc4", self.modelOfContent.authorid, self.modelOfContent.author];
        }
        NSString *cookie = [NSString stringWithFormat:@"leepetphone%%5Bpassword%%5D=%@; leepetphone[source]=ios; leepetphone[uid]=%@; leepetphone[username]=%@", [[NSUserDefaults standardUserDefaults] stringForKey:@"password"], [[NSUserDefaults standardUserDefaults] stringForKey:@"uid"], [[[NSUserDefaults standardUserDefaults] stringForKey:@"username"] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]];
        if (![[[NSUserDefaults standardUserDefaults] stringForKey:@"loginState"] boolValue]) {
            cookie = @"";
        }
        
        [NetworkingHandle handleWorkData:url AndBody:body value:@{@"Content-Type" : @"application/x-www-form-urlencoded", @"Cookie" : cookie} handleBlock:^(id result) {
        }];
    }else {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"PushLoginVC" object:nil userInfo:nil];
    }
}



#pragma mark - 观察者 观察播放完毕 观察屏幕旋转
- (void)addNotificationCenters {
    //  注册观察者用来观察，是否播放完毕
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
}


#pragma mark 播放结束后的代理回调
- (void)moviePlayDidEnd:(NSNotification *)notify {
    self.videoPic.hidden = NO;
    for (int i = 0 ; i < 2; i++) {
        UIView *view = [self viewWithTag:2333 + i];
        view.hidden = NO;
    }
}

- (void)handleTapActionPlay:(UITapGestureRecognizer *)tap {
    if (self.playerItem.status == AVPlayerItemStatusReadyToPlay) {
        self.videoPic.hidden = YES;
        for (int i = 0 ; i < 2; i++) {
            UIView *view = [self viewWithTag:2333 + i];
            view.hidden = YES;
        }
        CMTime dragedCMTime = CMTimeMake(0, 1);
        [self.player seekToTime:dragedCMTime completionHandler:^(BOOL finished) {
            
            [self.player play];
            
        }];
    }
    
}


+ (CGFloat)handleForHeightWithModel:(ModelOfDetailOfPage *)model {
    CGFloat height = 0;
    
    for (int i = 0 ; i < model.message.count; i++) {
        
        if ([[model.message[i] valueForKey:@"type"] isEqualToString:@"article"]) {
            
            CGRect contentRect = [model.content boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]} context:nil];
            height += contentRect.size.height + 10;
        }else if ([[model.message[i] valueForKey:@"type"] isEqualToString:@"video"]){
            height += [UIScreen mainScreen].bounds.size.width - 30 + 10;
        }else {
            
            CGFloat heightImage = ([UIScreen mainScreen].bounds.size.width - 30) * [[model.message[i] objectForKey:@"height"] floatValue] / [[model.message[i] objectForKey:@"width"] floatValue];
            height += heightImage + 10;
            
        }
      
    }

    return height + 10 + 50 + 20 + 5 + 50 + 5 + 30 + 35;
}


@end
